package com.example.exam;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Main2Activity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();

    }

    private void initView() {
        webView = (WebView) findViewById(R.id.webView);
        webView.loadUrl("file:///android_asset/hhh.html");
        webView.getSettings().setJavaScriptEnabled(true);
        webView.addJavascriptInterface(new JavaScriptInterface(this), "nativeMethod");
    }

    public class JavaScriptInterface {
        Activity mActivity;
        JavaScriptInterface(Activity mActivity) {
            this.mActivity = mActivity;
        }
        @JavascriptInterface
        public void startActivity(int i) {
            Log.v("TAG","asddfa"+i);
            Toast.makeText(mActivity,i+"",Toast.LENGTH_SHORT).show();
            Intent intent= new Intent(Main2Activity.this,Main3Activity.class);
            intent.putExtra("sign",i);
            Main2Activity.this.startActivity(intent);
        }
    }
}
